/* 页面逻辑 */
navigator.serviceWorker.register('./sw.js').then(function () {
    console.log('Service Worker 注册成功');
});

/* 页面逻辑 */
navigator.serviceWorker.addEventListener('message', function (e) {
    const data = e.data;
    const text = '[receive] ' + data.msg + ' —— tab ' + data.from;
    console.log('[Service Worker] receive message:', text);
});

/* 页面逻辑 */
navigator.serviceWorker.controller.postMessage('mydata');